<?php
    $url = new Url();
    $arr_status = LoadConfig::$status;
?>
<script type="text/javascript" src="<?php echo Yii::app()->params['tiny_url_cp'];?>js/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->params['static_url_cp'];?>js/tinymce_submit.js"></script>
<script type="text/javascript">
    function ajaxUpdateEvent(){
        tinyMCE.triggerSave();
        var strUrl = "<?php echo $url->createUrl("event/ajaxUpdateEvent") ?>";
        var id = '<?php echo $data["id"]?>';
        $.ajax({
            type: "POST",
            url: strUrl,
            data: {
                id:id,
                title:$("#title").val(),
                title_game:$("#title_game").val(),
                introtext:$("#introtext").val(),
                description:$("#description").val(),
                status:$("#status").val(),
            },
            success: function(msg){
                if(msg == 1){
                    alert('Update thành công');
                    window.location = '<?php echo $url->createUrl("event/index")?>';
                }else{
                    $("#show_error").html(msg);
                }
            },
            beforeSend:function(){
                $("#button_save").attr("disabled","disabled");
            },
            complete:function(){
                $("#button_save").removeAttr("disabled"); 
            }            
        });
    }
</script>
<div class="main clearfix">
    <div class="box clearfix bottom30">
        <ul class="form4">
            <li class="clearfix"><label><strong>Tiêu đề </strong>:</label>
                <div class="filltext">
                    <input type="text" style="width:360px" value="<?php echo $data['title']; ?>" id="title"> 
                </div>
            </li>
            <li class="clearfix"><label><strong>Tên Game </strong>:</label>
                <div class="filltext">
                    <select style="width:203px;" id="title_game">
                        <?php foreach($title_game as $key=>$value){?>
                            <option  value="<?php echo $key."|".$value;?>" <?php echo $data['gameId']==$key? 'selected="selected"' : '' ; ?> ><?php echo $value?></option>
                            <?php }?>
                    </select>
                </div>
            </li>
            <li class="clearfix"><label><strong>Trạng thái</strong>:</label>
                <div class="filltext">
                    <select style="width:203px;" id="status">
                        <?php foreach($arr_status as $key=>$value){?>
                            <option value="<?php echo $key;?>" <?php echo $data["status"]==$key ? 'selected="selected"':''; ?>><?php echo $value?></option>
                            <?php }?>
                    </select>
                </div>
            </li>

            <li class="clearfix"><label><strong>Tóm tắt</strong>:</label>
                <div class="filltext">
                    <textarea cols="5" rows="5" style="width:624px; height:120px" id="introtext"><?php echo $data['introtext']; ?></textarea>
                </div>
            </li>
            <li class="clearfix"><label><strong>Chi tiết</strong>:</label>
                <div class="filltext">
                    <textarea cols="5" rows="5" style="width:400px; height:120px" id="description"><?php echo $data['description']; ?></textarea>
                </div>
            </li>
            <li class="clearfix"><label>&nbsp;</label>
                <div class="filltext">
                    <input id="button_save" type="button" value=" Cập nhật " class="btn-bigblue" onclick="ajaxUpdateEvent();"> 
                    &nbsp;
                    <input onclick="history.go(-1)" type="button" value=" Quay lại " class="btn-bigblue">
                </div>
            </li>
            <li class="clearfix"><label>&nbsp;</label>
                <div class="filltext" style="color: red;" id="show_error"></div>
            </li>
        </ul>

    </div>
</div>